package com.zcx.qshop.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class CouponView extends LinearLayout {

    @BoundView(R.id.view_coupon_price) private TextView price;

    @BoundView(R.id.view_coupon_content) private TextView content;

    @BoundView(R.id.view_coupon_time) private ViewGroup time;

    @BoundView(R.id.view_coupon_is_end) private ImageView isEnd;

    @BoundView(R.id.view_coupon_backgound) private View backgound;

    public CouponView(Context context, AttributeSet attrs) {

        super(context, attrs);

        BoundViewHelper.boundView(this, QSApplication.ScaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(context).inflate(R.layout.view_coupon, this)));

    }

    public void setLoad(String price, String fullprice, String endtime, boolean isEnd){

        this.price.setText("￥" + price);

        this.content.setText("满" + fullprice + "元即可使用" + price + "元优惠券");

        ((TextView)this.time.getChildAt(1)).setText(endtime);

        ((TextView)this.time.getChildAt(1)).setTextColor(Color.parseColor(isEnd ? "#333333" : "#d3d3d3"));

        ((TextView)this.time.getChildAt(0)).setTextColor(Color.parseColor(isEnd ? "#333333" : "#d3d3d3"));

        this.isEnd.setVisibility(isEnd ? View.GONE : View.VISIBLE);

        backgound.setBackgroundResource(isEnd ? R.mipmap.coupon_blue : R.mipmap.coupon_gray);

        setVisibility(isEnd ? View.VISIBLE : View.GONE);

    }

}
